home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / mail-tools / thor / thor_2.22 / thor.lha / rexx / BBSRead / AddAmiNetFileList.br next >
Text File  |  1995-12-18  |  3KB  |  158 lines

  1. /* AddAmiNetFileList.br
  2.  *
  3.  * Arexx script to add a AmiNet RECENT/INDEX list to the database.
  4.  *
  5.  * Based on AddAmiNetFileList.br v3.1 provided by the THOR team.
  6.  *
  7.  * Modified by Henrik Dissing to handle dates and file sizes correctly.
  8.  *
  9.  */
  10.  
  11.     options results
  12.     /* trace results */
  13.  
  14.     parse arg argument
  15.  
  16.     template = 'BBSNAME/A,FILENAME/A'
  17.  
  18.     if(argument = '' | argument = '?') then
  19.     do
  20.         say '$VER: AddAminetFileList.br V3.2 (15.10.95)'
  21.         say 'Template:' template
  22.         exit
  23.     end
  24.  
  25.     if ~show('p', 'BBSREAD') then do
  26.         address command
  27.             "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  28.             "WaitForPort BBSREAD"
  29.     end
  30.  
  31.     address BBSREAD
  32.  
  33.     READARGS template ARGS CMDLINE argument
  34.     if(rc ~= 0) then 
  35.     do
  36.         say BBSREAD.LASTERROR
  37.         exit
  38.     end
  39.  
  40.     if(~OPEN(fh,ARGS.FILENAME,'Read')) then 
  41.     do
  42.         say 'Unable to open file'
  43.         exit
  44.     end
  45.  
  46.     rc = 0
  47.     signal on ERROR
  48.     signal on BREAK_C
  49.     signal on HALT
  50.  
  51.     BUFMODE COPYBACK        /* Enable copyback buffer mode */
  52.  
  53.     aline = readln(fh)
  54.     ltype = word(aline, 2) 
  55.     ldate = word(aline, words(aline))
  56.  
  57.     parse var ldate day '-' month '-' year
  58.     day = right(day, 2, '0')
  59.     select
  60.         when month == 'Jan' then month = '01'
  61.         when month == 'Feb' then month = '02'
  62.         when month == 'Mar' then month = '03'
  63.         when month == 'Apr' then month = '04'
  64.         when month == 'May' then month = '05'
  65.         when month == 'Jun' then month = '06'
  66.         when month == 'Jul' then month = '07'
  67.         when month == 'Aug' then month = '08'
  68.         when month == 'Sep' then month = '09'
  69.         when month == 'Oct' then month = '10'
  70.         when month == 'Nov' then month = '11'
  71.         when month == 'Dec' then month = '12'
  72.         otherwise
  73.             say "Unexpected month identifier in header:" month
  74.             goto HALT
  75.     end
  76.     year = right(year, 2, '0')
  77.     if year < 95 then
  78.         year = '20'year
  79.     else
  80.         year = '19'year
  81.     ldate = date('i', year || month || day, 's') * 86400
  82.  
  83.     do until eof(fh)
  84.         aline = readln(fh)
  85.  
  86.         do while(left(aline, 1) = '|')
  87.             aline  = readln(fh)
  88.         end
  89.  
  90.         if (aline == "") then iterate
  91.  
  92.         if ltype == "Complete" then
  93.         do
  94.             parse var aline 1 fname 20 farea 31 fsize 36 fage 40 fdesc
  95.             fname = strip(fname)
  96.             farea = strip(farea)
  97.             fsize = strip(fsize)
  98.             fdate = ldate - (strip(fage, 'B', ' +') * 7 * 86400)
  99.             fdesc = strip(fdesc)
  100.         end
  101.         else if ltype == "Recent" then
  102.         do
  103.             parse var aline 1 fname 20 farea 31 fsize 36 fdesc
  104.             fname = strip(fname)
  105.             farea = strip(farea)
  106.             fsize = strip(fsize, 'B', ' +')
  107.             fdate = ldate
  108.             fdesc = strip(fdesc)
  109.         end
  110.         else
  111.         do
  112.             say "Unexpected format of first line in" ARGS.FILENAME
  113.             goto HALT
  114.         end
  115.  
  116.         if right(fsize, 1) == 'M' then mega = 1
  117.         else mega = 0
  118.         fsize = compress(fsize, 'KM')
  119.  
  120.         if ~datatype(fsize,'N') then fsize = 0
  121.  
  122.         if mega == 1 then
  123.             fsize = trunc(fsize * 1024.0)
  124.         fsize = fsize * 1024
  125.  
  126.         say left(aline, 30)
  127.  
  128.         CONFIGFAREA '"' || ARGS.BBSNAME || '"' farea 
  129.  
  130.         if(fdesc ~= '') then
  131.         do
  132.             drop BRFILE.
  133.  
  134.             BRFILE.NAME = fname
  135.             BRFILE.SIZE = fsize
  136.             BRFILE.DATE = fdate
  137.  
  138.             BRFILE.DESCRIPTION.COUNT = 1
  139.             BRFILE.DESCRIPTION.1 = fdesc
  140.  
  141.             WRITEBRFILE '"' || ARGS.BBSNAME || '"' farea stem BRFILE 
  142.  
  143.         end
  144.     end
  145.  
  146. ERROR:
  147. HALT:
  148. BREAK_C:
  149.  
  150.     if(rc ~= 0) then 
  151.     do
  152.         say 'Error' rc 'in line' SIGL ':' BBSREAD.LASTERROR
  153.     end
  154.  
  155.     BUFMODE ENDCOPYBACK        /* Disable copyback buffer mode */
  156.  
  157.     exit
  158.